package render

import (
	"MetroBuilderGameJam/gameEngine/drawer"
	"MetroBuilderGameJam/gameEngine/geom"
	"github.com/hajimehoshi/ebiten/v2"
)

func NewColliderRenderer(d *drawer.Drawer) *Collider {
	return &Collider{
		drawer: d,
	}
}

type Collider struct {
	drawer *drawer.Drawer
}

func (c *Collider) Draw(screen *ebiten.Image, item geom.Collider) geom.Collider {
	c.drawCollider(screen, item)
	return item
}

func (c *Collider) drawCollider(screen *ebiten.Image, item geom.Collider) geom.Collider {
	switch item.(type) {
	case *geom.ColliderCircle:
		circle := item.(*geom.ColliderCircle)
		c.drawer.Point(screen, circle.Pivot, 3, drawer.ColorGreen)
		c.drawer.Circle(screen, circle.Pivot, circle.Radius, 5, drawer.ColorGreen)
	case *geom.ColliderRectangle:
		r := item.(*geom.ColliderRectangle)
		c.drawer.Point(screen, r.Pivot, 3, drawer.ColorGreen)
		c.drawer.SimpleRectangle(screen, r.Pivot, r.Size, 5, drawer.ColorGreen)
	case *geom.ColliderPoint:
		p := item.(*geom.ColliderPoint)
		c.drawer.Point(screen, p.Pivot, 2, drawer.ColorGreen)
	case *geom.ColliderTriangle:
		t := item.(*geom.ColliderTriangle)
		c.drawer.Point(screen, t.Pivot, 3, drawer.ColorGreen)
		c.drawer.Triangle(screen, t.Pivot, t.A, t.B, t.C, 5, drawer.ColorGreen)
	case *geom.ColliderSet:
		set := item.(*geom.ColliderSet)
		for _, collider := range set.GetColliders() {
			c.drawCollider(screen, collider)
		}
	}

	return item
}
